package cn.dengqiang.org.service.impl;

import cn.dengqiang.basic.exception.BusinessException;
import cn.dengqiang.basic.service.impl.BaseServiceImpl;
import cn.dengqiang.org.domain.Department;
import cn.dengqiang.org.domain.Employee;
import cn.dengqiang.org.domain.Shop;
import cn.dengqiang.org.mapper.DepartmentMapper;
import cn.dengqiang.org.mapper.EmployeeMapper;
import cn.dengqiang.org.mapper.ShopMapper;
import cn.dengqiang.org.service.IDepartmentService;
import cn.dengqiang.org.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class ShopServiceImpl extends BaseServiceImpl<Shop> implements IShopService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Autowired
    private ShopMapper shopMapper;

    @Override
    public void settledIn(Shop shop) {
        //对用户进行效验
        Employee admin = shop.getAdmin();
        Employee employee1 = employeeMapper.loadByUser(admin);
        Employee employee = employee1;
        if (employee!=null)//如果不为空
            throw new BusinessException("你已经注册请直接登录");
        //为空就执行下面
        //保存员工并返回自增id
        employeeMapper.save(admin);
        System.out.println(admin);
        shopMapper.save(shop);

        System.err.println(shop);
        //让管理员关联店铺id
        admin.setShop(shop);
        employeeMapper.update(admin);
    }
}
